package com.example.myapplication.BIM;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.example.day01.R;

public class BIMHealthActivity extends AppCompatActivity implements View.OnClickListener {
    private static final String TAG = "BIMHealthActivity";
    EditText et_height,et_weight;
    RadioGroup sexRg;
    RadioButton rb_boy,rb_girl;
    Button btn_start,btn_reStart;
    double weight;
    double height;
    String sex="";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_b_i_m_health);
        initView();
    }

    private void initView() {
        et_height=findViewById(R.id.et_bim_height);
        et_weight=findViewById(R.id.et_bim_weight);
        sexRg=findViewById(R.id.bim_rg);
        btn_start=findViewById(R.id.bim_start);
        btn_start.setOnClickListener(this);
        btn_reStart=findViewById(R.id.bim_re_start);
        btn_reStart.setOnClickListener(this);
        rb_boy=findViewById(R.id.bim_rb_boy);
        rb_girl=findViewById(R.id.bim_rb_girl);
    }

    @Override
    public void onClick(View v) {

        weight = Double.parseDouble(et_weight.getText().toString());
        height = Double.parseDouble(et_height.getText().toString());


        Intent intent = new Intent();

        switch (v.getId()) {
            case R.id.bim_start:

                if (rb_boy.isChecked()==true) {
                   sex="男";
                }
                if (rb_girl.isChecked()==true) {
                    sex="女";
                }
                intent.putExtra("sex",sex);
                Log.d(TAG, "xinbie"+sex);
                intent.setClass(this,BimResultActivity.class);
                intent.putExtra("weight",weight);
                Log.d(TAG, "weight: "+weight);
                intent.putExtra("height",height);
                Log.d(TAG, "height: "+height);
                startActivity(intent);
                break;
            case R.id.bim_re_start:
                break;
        }
        startActivity(intent);
    }
}
